#include "myfileselect.h"
#include <QDialogButtonBox>
#include <QLineEdit>
#include "filefilterproxymodelforbackup.h"

MyFileSelect::MyFileSelect(QWidget* parent) :
    QFileDialog(parent)
{
    this->setViewMode(QFileDialog::Detail);
    this->setFileMode(QFileDialog::ExistingFiles);
    this->setFilter(QDir::System | QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);

    FileFilterProxyModeForBackup *proxy = new FileFilterProxyModeForBackup;
    this->setProxyModel(proxy);

    QDialogButtonBox* button = this->findChild<QDialogButtonBox*>("buttonBox");
    disconnect(button, SIGNAL(accepted()), this, SLOT(accept()));
    connect(button, SIGNAL(accepted()), this, SLOT(goAccept()));

    QLineEdit *fileNameEdit = this->findChild<QLineEdit*>("fileNameEdit");
    connect(this, &MyFileSelect::currentChanged, this, [=](const QString& path){
        fileNameEdit->setText(path.section('/', -1));
    });
}

void MyFileSelect::goAccept()
{
    QDialog::accept();
}

MyFileSelect::~MyFileSelect()
{}
